package com.vue3.blog.web;

import com.vue3.blog.common.resp.PageVO;
import com.vue3.blog.common.resp.Result;
import com.vue3.blog.domain.entity.CategoryEntity;
import com.vue3.blog.domain.vo.CategoryVO;
import com.vue3.blog.service.ICategoryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Mr.小朱同学
 * @version 1.0.0
 * @date 2025/6/12 12:27
 * @description 文章分类
 */
@RestController
@RequestMapping("/api/category")
public class CategoryController {
    @Resource
    private ICategoryService categoryService;

    @PostMapping("/save")
    public Result<Void> save(@RequestBody CategoryEntity entity) {
        categoryService.saveCategory(entity);
        return Result.success("新增成功");
    }

    @DeleteMapping("/delete/{id}")
    public Result<Void> remove(@PathVariable Long id) {
        categoryService.removeCategory(id);
        return Result.success("删除成功");
    }

    @GetMapping("/drop-list")
    public Result<List<CategoryEntity>> dropList() {
        return Result.success("分类下拉列表", categoryService.dropList());
    }

    @GetMapping("/list")
    public Result<PageVO<CategoryVO>> list(String name) {
        return Result.success("分类列表", categoryService.getCategoryList(name));
    }

}